import { defineConfig } from "vite";
import vue from "@vitejs/plugin-vue";
// import AutoImport from "unplugin-auto-import/vite";
// import Components from "unplugin-vue-components/vite";
import { ElementPlusResolver } from "unplugin-vue-components/resolvers";
import { viteMockServe } from "vite-plugin-mock";
import path from "path";
const resolve = (dir: string) => path.join(__dirname, dir);
export default defineConfig({
  plugins: [
    vue(),
    // AutoImport({
    //   resolvers: [ElementPlusResolver()],
    // }),
    // Components({
    //   resolvers: [ElementPlusResolver()],
    // }),
    viteMockServe({ supportTs: false })
  ],
  resolve: {
    alias: {
      "@": resolve("src"),
      cmp: resolve("src/component"),
      view: resolve("src/view"),
      utils: resolve("src/utils"),
      router: resolve("src/router"),
      store: resolve("src/store"),
      assets: resolve("src/assets"),
      style: resolve("src/assets/style"),
      lib: resolve("src/lib"),
    },
  },
  server: {
    //服务器主机名
    host: "0.0.0.0",
    //端口号
    port: 9280,
    //设为 true 时若端口已被占用则会直接退出，而不是尝试下一个可用端口
    strictPort: false,
    //服务器启动时自动在浏览器中打开应用程序,当此值为字符串时，会被用作 URL 的路径名
    open: false,
    //自定义代理规则
    proxy: {
      // 选项写法
      "/dev-api": {
        target: "https://www.fastmock.site/mock/c0ea1b4203ef74fa9714f503a52cc731/ptApi",
        changeOrigin: true,
        rewrite: (path) => path.replace(/^\/dev-api/, ""),
      },
    },
  },
});
